﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace QUAN_LY_MUON_TRA_SACH
{
    public class AnalysisDB
    {
        private string strError = "";
        public string StrError
        {
            get { return strError; }
            set { strError = value; }
        }
        public int ExcuteNonQuery(string strSQL, CommandType commandType)
        {
            int effectRecord = 0;
            SqlCommand Com = new SqlCommand(strSQL, Connection.sqlConnection);
            Com.CommandType = commandType;
            try
            {
                effectRecord = Com.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                strError = "Error: " + ex.Message;
            }
            return effectRecord;
        }
        public object ExcuteScalar(string strSQL, CommandType commandType)
        {
            object objValue = null;
            SqlCommand Com = new SqlCommand(strSQL, Connection.sqlConnection);
            Com.CommandType = commandType;
            try
            {
                objValue = Com.ExecuteScalar();
            }
            catch (Exception ex)
            {
                strError = "Error: " + ex.Message;
            }
            return objValue;
        }
        public object[] GetObjects(string strSQL, CommandType commandType)
        {
            object[] info = null;
            try
            {
                SqlCommand Com = new SqlCommand(strSQL, Connection.sqlConnection);
                Com.CommandType = commandType;
                SqlDataReader sqlDataReader = Com.ExecuteReader();
                if (sqlDataReader.Read())
                {
                    info = new object[sqlDataReader.FieldCount];
                    sqlDataReader.GetValues(info);
                }
                sqlDataReader.Close();
                sqlDataReader.Dispose();
            }
            catch (Exception ex)
            {
                strError = "Error: " + ex.Message;
            }
            return info;
        }
    }
}
